/*
 * Copyright (C) 2012  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.swing.util;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;

/**
 * NeutralAction : A neutral action can be added to any {@link AbstractButton}
 * wihtout changing its properties (text, icon, shortcut, etc.).
 * 
 * @author Romain DUBOIS
 */
public abstract class NeutralAction extends AbstractAction {

    /** Serial version */
    private static final long serialVersionUID = 1L;

    /**
     * Constructor.
     */
    public NeutralAction() {
        super();
    }

    /**
     * Constructor.
     * 
     * @param pButton
     *            The button to take data from
     */
    public NeutralAction(final AbstractButton pButton) {
        super(pButton.getText(), pButton.getIcon());

        putValue(Action.MNEMONIC_KEY, Integer.valueOf(pButton.getMnemonic()));
        putValue(Action.SHORT_DESCRIPTION, pButton.getToolTipText());
        putValue(Action.ACTION_COMMAND_KEY, pButton.getActionCommand());
        setEnabled(pButton.isEnabled());
        putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY,
                Integer.valueOf(pButton.getDisplayedMnemonicIndex()));
    }

}
